import apiClient from './client';
import { 
  StudentRecordItem, MyCoachItem, MyApplyItem, 
  UserProgressStepItem, CarProgressResponseItem, 
  ProcessStepImageItem, DriverHospitalItem, FileItem,
  UserSubjectScoreItem, UserScoreVideoItem, CarProgressStatisticsItem
} from '../types/myself';


/**
 * 获取我的教练信息
 * @returns 教练列表
 */
export const getMyCoachApi = async (): Promise<{
  code: number;
  message: string;
  data: MyCoachItem[];
}> => {
  return apiClient.get('/api/myself/v1/coach');
};

export const getMyCoachInfoApi = async (): Promise<{
  code: number;
  message: string;
  data: MyCoachItem;
}> => {
  return apiClient.get('/api/myself/v1/teacher');
};


/**
 * 获取我的申请信息
 * @returns 申请列表
 */
export const getMyApplyApi = async (): Promise<{
  code: number;
  message: string;
  data: MyApplyItem;
}> => {
  return apiClient.get('/api/myself/v1/subscribe');
};

/**
 * 创建学籍申请表
 * @returns 申请列表
 */
export const createStudentRecordApi = async (
    student: StudentRecordItem,
): Promise<{
    data: StudentRecordItem;
    code: number;
    message: string;
}> => {
    return apiClient.post('/api/myself/v1/subscribe', {
        ...student
    });
};

/**
 * 获取学车进度
 * @returns 申请列表
 */
export const getCarProgressStepApi = async (): Promise<{
  code: number;
  message: string;
  data: CarProgressResponseItem;
}> => {
  return apiClient.get('/api/myself/v1/car-process');
};

/**
 * 获取我的学车进度
 * @returns 申请列表
 */
export const getUserProgressStepApi = async (step_id: number = 0): Promise<{
  code: number;
  message: string;
  data: UserProgressStepItem[];
}> => {
  return apiClient.get('/api/myself/v1/my-process', {
      step_id: step_id
  });
};

/**
 * 获取我的学籍所在城市
 * @returns 申请列表
 */
export const getUserApplyCityApi = async (): Promise<{
  code: number;
  message: string;
  data: {
    city_code: number[];
    city_name: string;
  };
}> => {
  return apiClient.get('/api/myself/v1/apply-city');
};

/**
 * 获取进度图片
 * @returns 申请列表
 */
export const getProcessStepImageApi = async (step_id: number, category: string = 'processStep'): Promise<{
  code: number;
  message: string;
  data: ProcessStepImageItem[];
}> => {
  return apiClient.get('/api/myself/v1/image', {
      step_id: step_id,
      category: category
  });
};


/**
 * 获取驾驶员体检医院
 * @returns 驾驶员体检医院列表
 */
export const getDriverHospitalApi = async (city_id: number): Promise<{
  code: number;
  message: string;
  data: DriverHospitalItem[]
}> => {
  return apiClient.get('/api/myself/v1/driver_hospital', {
      city_id: city_id
  });
};

/**
 * 更新进度的子步骤
 * @returns 申请列表
 */
export const setProcessChildrenStatusApi = async (step_id: number, children: string, total: number): Promise<{
  code: number;
  message: string;
  data: {
    status: number,
    created_at: string
  };
}> => {
  return apiClient.put('/api/myself/v1/my-process', {
    step_id: step_id,
    child: children,
    status: 1,
    total: total
  });
};

/**
 * 更新进度的状态
 * @returns 申请列表
 */
export const setUserProgressStepStatusApi = async (step_id: number, status: number): Promise<{
  code: number;
  message: string;
  data: {
    status: number,
    created_at: string
  };
}> => {
  return apiClient.post('/api/myself/v1/my-process', {
    step_id: step_id,
    status: status
  });
};


/**
 * 更新进度的状态
 * @returns 申请列表
 */
export const getMyInterviewResultApi = async (): Promise<{
  code: number;
  message: string;
  data: {
    date: string;
    address: string;
  };
}> => {
  return apiClient.get('/api/myself/v1/interview');
};


/**
 * 获取我的考试成绩
 * @returns 考试成绩列表
 */
export const getUserSubjectScoreApi = async (): Promise<{
  code: number;
  message: string;
  data: UserSubjectScoreItem;
}> => {
  return apiClient.get('/api/subject/v1/score');
};


/**
 * 更新我的考试成绩
 * @returns 考试成绩列表
 */
export const setUserSubjectScoreApi = async (subject: any, files: FileItem[]): Promise<{
  code: number;
  message: string;
  data: UserScoreVideoItem[];
}> => {
  return apiClient.post('/api/subject/v1/score', {
    subject,
    files
  });
};


export const deleteUserFileApi = async (file_id: string, file_url: string): Promise<{
  code: number;
  message: string;
}> => {
  return apiClient.delete('/api/subject/v1/file', {
    file_id,
    file_url
  });
}


export const getCarProgressStatisticsApi = async (): Promise<{
  code: number;
  message: string;
  data: CarProgressStatisticsItem;
}> => {
  return apiClient.get('/api/myself/v1/process-statistics');

}